package com.xr.hr.personnel;

import java.util.List;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.utils.variant.VariantSet;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * ecfiQueryViewModel
 */
public class ecfiQueryViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
    // Add your code here
    super.doUpdateData(parameters, outParameters);
  }
  public void checkEcfiDate(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset ds= getDataset("datasetCondition");
	  String sql="select ecfi.hritems_id,oos.onoff_station_id from org_employee emp, org_onoff_station oos, org_company com,org_dept dept,wf_ecfi ecfi where emp.employee_id = oos.employee_id and com.company_id = oos.company_id and com.company_id=dept.company_id and oos.onoff_station_id=ecfi.onoff_station_id and oos.dept_id=dept.dept_id and emp.dr = 0 ";
	  if(ds.getString("EMPLOYEE_NAME")!=null && !ds.getString("EMPLOYEE_NAME").equals("")){
		  sql+=" and emp.employee_name like '%"+ds.getString("EMPLOYEE_NAME")+"%'";
	  }
	  if(ds.getString("EMPLOYEE_CODE")!=null && !ds.getString("EMPLOYEE_CODE").equals("")){
		  sql+=" and emp.EMPLOYEE_CODE like '%"+ds.getString("EMPLOYEE_CODE")+"%'";
	  }
	  if(ds.getString("ID_CARD_NUM")!=null && !ds.getString("ID_CARD_NUM").equals("")){
		  sql+=" and emp.ID_CARD_NUM like '%"+ds.getString("ID_CARD_NUM")+"%'";
	  }
	  if(ds.getString("COMPANY_NAME")!=null && !ds.getString("COMPANY_NAME").equals("")){
		  sql+=" and com.COMPANY_NAME like '%"+ds.getString("COMPANY_NAME")+"%'";
	  }
	  if(ds.getString("DEPT_NAME")!=null && !ds.getString("DEPT_NAME").equals("")){
		  sql+=" and com.DEPT_NAME like '%"+ds.getString("DEPT_NAME")+"%'";
	  }
	  if(ds.getString("OOS_STATUS")!=null && !ds.getString("OOS_STATUS").equals("")){
		  sql+=" and oos.status = '"+ds.getString("OOS_STATUS")+"'";
	  }
	  if(ds.getString("HRITEMS_ID")!=null && !ds.getString("HRITEMS_ID").equals("")){
		  sql+=" and ecfi.HRITEMS_ID = '"+ds.getString("HRITEMS_ID")+"'";
	  }
	  dbs.setSql(sql);
	  List list= dbs.queryForList();
	  for(int i=0;i<list.size();i++){
		  VariantSet vs=(VariantSet)list.get(i);
		  dbs.setSql("begin pck_hr.checkEcfi("+vs.getString("onoff_station_id")+","+vs.getString("hritems_id")+"); end;");
		  dbs.execute();
	  }
	  dbs.close();
//super.doUpdateData(parameters, outParameters);
}
}
